package com.mavenq.fly.test;

import lombok.SneakyThrows;

import java.util.concurrent.CountDownLatch;

public class CountDownDemo {

    public static void main(String[] args) {
        CountDownLatch countDownLatch = new CountDownLatch(3);
        new Thread(new Runnable() {
            @SneakyThrows
            @Override
            public void run() {
                countDownLatch.await();
                countDownLatch.countDown();
                System.out.println("线程1执行了");
            }
        }).start();

        new Thread(new Runnable() {
            @SneakyThrows
            @Override
            public void run() {
                countDownLatch.await();
                System.out.println("线程2执行了");
            }
        }).start();

        new Thread(new Runnable() {
            @SneakyThrows
            @Override
            public void run() {
                countDownLatch.countDown();
                System.out.println("线程3执行了");
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                countDownLatch.countDown();
                System.out.println("线程4执行了");
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                countDownLatch.countDown();
                System.out.println("线程5执行了");
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                countDownLatch.countDown();
                System.out.println("线程6执行了");
            }
        }).start();
    }
}
